Skip to content

Conversation

@yhzdys
Copy link
Contributor

@yhzdys yhzdys commented Jan 16, 2026

Add ExchangeIdGenerator interface to allow users to customize exchange ID generation in HTTP clients.

This change introduces the ExchangeIdGenerator interface, which enables users to provide custom strategies for generating exchange identifiers. This is particularly useful in distributed systems where custom tracing and correlation mechanisms are required.

Comment on lines 463 to 480
/**
* @since 5.1
*/
public void setExchangeId(final String exchangeId) {
this.exchangeId = exchangeId;
}

/**
* @since 5.7
*/
public String setExchangeId(final Supplier<String> supplier) {
final String exchangeId = this.exchangeId; // avoid getfield opcode
if (exchangeId == null) {
return this.exchangeId = supplier.get();
} else {
return exchangeId;
}
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks incoherent. I'd expect the client builders to simply take a Supplier<String> exchangeIdSupplier, which defaults to ExecSupport::getNextExchangeId. The context classes shouldn't need to know about what supplies the exchange IDs, they should just know the exchange ID for the particular exchange they represent.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also, there should be a documented contract for custom exchange ID suppliers, i.e. they must return a unique, non-null, non-blank string every time they are called.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You're right. I'll refactor the implementation.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@rschmitt I've implemented the changes as discussed. The ExchangeIdGenerator interface has been added to allow custom exchange ID generation. Please review when convenient. Thank you!

@yhzdys yhzdys force-pushed the master branch 2 times, most recently from d6326b4 to 5069736 Compare January 17, 2026 03:55
@yhzdys yhzdys changed the title Allow pre-set custom ExchangeId in HttpClientContext before request Add custom ExchangeId generator support Jan 17, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants